//
//  HWXiuGaiMimaJiemianViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/11/8.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWXiuGaiMimaJiemianViewController.h"
#import "HWGuanlianPhoneTableViewCell.h"
#import "Countdown.h"


@interface HWXiuGaiMimaJiemianViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UIView *lowerPartView;
@property(strong,nonatomic) UITextField *oneTextField;
@property(strong,nonatomic) UITextField *twoTextfeild;


@end

@implementation HWXiuGaiMimaJiemianViewController

-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, CF_NavHeight+88) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
       // _mainaTableVie.backgroundColor = RGB(241, 242, 244);
        
    }
    return   _mainaTableVie;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
    
    
}


//设置UI
-(void)setupUI {
    self.navigationItem.title = @"重置密码";
    self.navigationItem.title =  [HWjianzhiduiObject keylocalization:@"重置密码"];
    
    self.view.backgroundColor = [UIColor whiteColor];
   // self.view.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.mainaTableVie];
    
    [self addLowerPartView];

}





// 添加低部UIview
- (void)addLowerPartView {
    
    self.lowerPartView = [[UIView alloc]initWithFrame:CGRectMake(0, CF_NavHeight+88+30, kScreenW, 44)];
    // self.lowerPartView.backgroundColor = [UIColor yellowColor];
    self.lowerPartView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.lowerPartView];
    NSString *quedin = [HWjianzhiduiObject keylocalization:@"确定" ];
    
    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(15, 0, kScreenW-15*2, 36) Title:quedin Image:nil Font:13 Color:RGB(255, 255, 155) Target:self Selector:@selector(buttonTap)];
    butt.backgroundColor = blueBackgroundBT;
    butt.layer.cornerRadius = 18;
    butt.layer.masksToBounds = YES;
    butt.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView:butt];
    
    [self.lowerPartView addSubview:butt];
    
    // 123456
    
}

- (void)buttonTap {
    
    NSLog(@"保存");
//    HWbangdingQQViewController *bangding = [[HWbangdingQQViewController alloc]init];
//    [self.navigationController pushViewController:bangding animated:YES];
    
    
    
     if (!(self.oneTextField.text.length > 0)) {
               [MBProgressHUD showError:@"旧密码不能为空"];
               return;
        } else if (!(self.twoTextfeild.text.length > 0)) {
            
            
             [MBProgressHUD showError:@"新密码不能为空"];
              return;
            
            
        } else if ([WMUtil isEmpty:self.oneTextField.text]) {
            
            
              [MBProgressHUD showError:@"密码不能有空格"];
               return;
            
        }else if ([WMUtil isEmpty:self.twoTextfeild.text]) {
            
            
              [MBProgressHUD showError:@"密码不能有空格"];
               return;
            
        }
    
    
   
    
    
        
        
          NSString *userID = [HWLocallyStoredData getLoginUserID];
          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
          NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
          NSString *signMD5 = [WMUtil md5HexDigest:sign];
          NSDictionary *parametes = @{
                                     @"ct" :  @"app",
                                     @"ac" : @"edit_passwd",
                                     @"ios" : @"1",
                                     @"oldpasswd" : self.oneTextField.text,
                                     @"uid" :userID,
                                     @"t" :tStr,
                                     @"sign": signMD5,
                                     @"passwd": self.twoTextfeild.text,
                                     @"repasswd" :self.twoTextfeild.text
                                     
                                     };
         
         [MBProgressHUD show:@"正在修改密码"];
         
         [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
             
           
             NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
          //   [MBProgressHUD hideHUD];
             
             
             if ([codeStr intValue] == 1) {
               
           
                 [MBProgressHUD  showSuccess:response[@"message"]];
                 [self.navigationController popViewControllerAnimated:YES];
                 
                

             } else {
              
                  [MBProgressHUD  showSuccess:response[@"message"]];
                 
             }
             NSLog(@"%@",response);
             
             
         } failure:^(NSString *error) {

             [MBProgressHUD  showError:@"绑定邮箱成功"];
            
         }];
    
    
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {
    
    static NSString *cellID = @"cellID";
    
    HWGuanlianPhoneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[HWGuanlianPhoneTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
    }
     cell.codeBut.hidden = YES;
    if (indexPath.row == 0) {
        
        cell.namelabel.text = @"旧密码";
        cell.namelabel.text =  [HWjianzhiduiObject keylocalization: @"旧密码"];
        
        cell.codeBut.hidden = YES;
        
        NSString *zidfu = [HWjianzhiduiObject keylocalization:@"6-15个字符，区分大小写"];
        
       NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:zidfu attributes:
                   @{NSForegroundColorAttributeName:RGB(153, 153, 153),
                     NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
                   ];
      cell.titleTextField.attributedPlaceholder  = attrString;
        self.oneTextField =   cell.titleTextField;
        
        
    } else if (indexPath.row == 1) {
        
         cell.namelabel.text = @"新密码";
        
        cell.namelabel.text = [HWjianzhiduiObject keylocalization:@"新密码"];
        
        
         cell.codeBut.hidden = YES;
        
        NSString *zaici = [HWjianzhiduiObject keylocalization:@"请再次输入密码"];
        
         NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:zaici attributes:
                         @{NSForegroundColorAttributeName:RGB(153, 153, 153),
                           NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
                         ];
         cell.titleTextField.attributedPlaceholder  = attrString;
        self.twoTextfeild = cell.titleTextField;
        
        
    }
    
   // [cell.codeBut addTarget:self action:@selector(xianshyanjTap:) forControlEvents:UIControlEventTouchUpInside];

    return  cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  44;
    
}



// 获取验证码
//- (void)xianshyanjTap:(UIButton *)sende {
//
////    if (![WMUtil validateMobile:self.titleTextField.text]) {
////
////        [MBProgressHUD showError:@"请输入正确的手机号"];
////        return ;
////
////
////    }
////
//
//
//    [Countdown  StartTimeCodeBtn:sende];
//
//
//
//
//
//
//
//    DLog(@"获取验证码");
//
//
//
//}









@end
